import datetime
import uuid
from applications.extensions import db


class LicenceInfo(db.Model):
    __tablename__ = 'licence_info'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='借阅证ID')
    phonenum = db.Column(db.String(128),db.ForeignKey('user.user_phonenum'), comment='电话号码')
    reg_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    out_time = db.Column(db.DateTime, default=datetime.datetime.now() + datetime.timedelta(days=365), comment='到期时间，创建时间后一年')
    status = db.Column(db.String(255), comment='状态', default=None)
    ispunish = db.Column(db.Boolean, default=False, comment='处罚状态')
    suspended_timeout = db.Column(db.DateTime, comment='暂停到期时间')
    licence_id = db.Column(db.String(255), unique=True, comment='借阅证id')

    def __init__(self, phonenum, status=None):
        self.phonenum = phonenum
        self.status = status
        self.licence_id = str(uuid.uuid4())
